print-editor: Allow opening files
authorMatthias Clasen <mclasen@redhat.com>
Sun, 28 Jun 2020 14:26:19 +0000 (10:26 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 28 Jun 2020 14:51:16 +0000 (10:51 -0400)
Since it calls itself an editor, it should really
support opening files on the commandline.

demos/print-editor/print-editor.c

index 158ea873b169c67f02a50cf32ec0d9a3b1d34bd8..f8fa0b4ef1385a59091ce13b800dc049f33fbd5b 100644 (file)
@@ -752,25 +752,6 @@ mark_set_callback (GtkTextBuffer     *text_buffer,
   update_statusbar ();
 }
 
-static gint
-command_line (GApplication            *application,
-              GApplicationCommandLine *command_line)
-{
-  int argc;
-  char **argv;
-
-  argv = g_application_command_line_get_arguments (command_line, &argc);
-
-  if (argc == 2)
-    {
-      GFile *file = g_file_new_for_commandline_arg (argv[1]);
-      load_file (file);
-      g_object_unref (file);
-    }
-
-  return 0;
-}
-
 static void
 startup (GApplication *app)
 {
@@ -845,6 +826,20 @@ activate (GApplication *app)
   gtk_widget_show (main_window);
 }
 
+static void
+open (GApplication  *application,
+      GFile        **files,
+      int            n_files,
+      const char    *hint)
+{
+  if (n_files > 1)
+    g_warning ("Can only open a single file");
+
+  activate (application);
+
+  load_file (files[0]);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -868,7 +863,7 @@ main (int argc, char **argv)
     g_clear_error (&error);
   }
 
-  app = gtk_application_new ("org.gtk.PrintEditor", 0);
+  app = gtk_application_new ("org.gtk.PrintEditor4", G_APPLICATION_HANDLES_OPEN);
 
   g_action_map_add_action_entries (G_ACTION_MAP (app),
                                    app_entries, G_N_ELEMENTS (app_entries),
@@ -876,7 +871,7 @@ main (int argc, char **argv)
 
   g_signal_connect (app, "startup", G_CALLBACK (startup), NULL);
   g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
-  g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL);
+  g_signal_connect (app, "open", G_CALLBACK (open), NULL);
 
   g_application_run (G_APPLICATION (app), argc, argv);